package com.example.md.mddemo.controller;

import com.example.md.mddemo.JsonResult;
import com.example.md.mddemo.entity.Customer;
import com.example.md.mddemo.entity.Person;
import com.example.md.mddemo.entity.value_obj.CustContactPerson;
import com.example.md.mddemo.repo.CustomerRepository;
import com.example.md.mddemo.services.CustomerService;
import com.example.md.mddemo.services.PersonService;
import org.bson.types.ObjectId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Copyright © 2018年 ziniuxiaozhu. All rights reserved.
 *
 * @Author 临江仙 hzqiuxm@163.com
 * TODO:亲爱的临江仙，请写点注释吧...........
 * @Date 2018/8/3 9:56
 */
@RestController
public class TestController {

    private static final Logger log = LoggerFactory.getLogger(TestController.class);

    @Autowired
    private PersonService personService;
    @Autowired
    private CustomerService customerService;

    /**
     * @return 无返回值
     */
    @GetMapping("/testAdd")
    public void testAdd(){

        Person person = new Person("jinguanghui",31);

        ArrayList<String> strings = new ArrayList<>();
        strings.add("浙江省杭州市余杭区");
        strings.add("浙江省杭州市之江区");
        person.setAddress(strings);

        Map<String,String> descrption = new HashMap<>();
        descrption.put("ext1","so");
        descrption.put("ext2","cool");

        person.setDes(descrption);

        personService.addPerson(person);
    }

    /**
     * 查询用户基本信息
     *
     * @param objId 唯一标识符|必填
     * @return 当前用户的所有基本信息
     * @resp code 返回码(0表示查询成功,其它表示失败)|string|必填
     */
    @GetMapping("/testGet")
    public JsonResult<Person> testGet(@RequestParam String objId){

        ObjectId objectId = new ObjectId(objId);
        return new JsonResult<>(personService.findPerson(objectId));

    }


    @GetMapping("/testGetAddress")
    public JsonResult<String> testGetAddress(@RequestParam String name){


        return new JsonResult<String>(personService.findAddressByName(name));

    }



    @GetMapping("/testGetCustcode")
    public JsonResult<List<List<CustContactPerson>>> testGetCustcode(@RequestParam String custcode){


        return new JsonResult<List<List<CustContactPerson>>>(customerService.findContactInfoByCustcode(custcode));

    }

    @GetMapping("/testGetCustcode2")
    public JsonResult<List<String>> testGetCustcode2(@RequestParam String custcode){


        return new JsonResult<List<String>>(customerService.findCustomerByCustCode(custcode));

    }


    @GetMapping("/testGetDes")
    public JsonResult<List<Person> > testGetValue(@RequestParam String des){


        return new JsonResult<List<Person> >(personService.findByDes(des));

    }
}
